"""devops URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
# from django.contrib import admin
from rest_framework.routers import DefaultRouter
from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
from rest_framework_jwt.views import obtain_jwt_token

from idcs.views import IdcViewset
from cabinet.views import CabinetViewset
from manufacturer.views import ManufacturerViewset, ProductModelViewset
from users.router import user_group_router
from servers.router import server_router
from permissions.router import permission_router
from business.router import business_router
from sqlaudit.router import sqlaudit_router
from workorder.router import workorder_router
# from tasks.router import task_router
from dashboard.router import dashboard_router

from utils.upload_view import FileUploadView


route = DefaultRouter()
route.register("idcs", IdcViewset, base_name='idc')
route.register("cabinet", CabinetViewset, base_name='cabinet')
route.register("manufacturer", ManufacturerViewset, base_name='manufacturer')
route.register("product", ProductModelViewset, base_name='product')

route.registry.extend(user_group_router.registry)
route.registry.extend(server_router.registry)
route.registry.extend(permission_router.registry)
route.registry.extend(business_router.registry)
route.registry.extend(sqlaudit_router.registry)
route.registry.extend(workorder_router.registry)
# route.registry.extend(task_router.registry)
route.registry.extend(dashboard_router.registry)

schema_view = get_schema_view(title='运维平台接口文档', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])

urlpatterns = [
    # url(r'^admin/', admin.site.urls),
    url(r'^docs/', schema_view),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest-framework')),  # DRF内置的session认证地址
    url(r'^', include(route.urls)),
    url(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view()),
]

# jwt 获取地址
urlpatterns += [
    url(r'^api-token-auth/', obtain_jwt_token),
]
